define(['ojs/ojcore', 'knockout', 'jquery', 'ojs/ojknockout', 'promise', 'ojs/ojinputtext', 'ojs/ojdatetimepicker', 'ojs/ojselectcombobox', 'ojs/ojcheckboxset', 'ojs/ojtable', 'ojs/ojdatacollection-utils', 'ojs/ojarraytabledatasource'], function(oj, ko, $) {
    function playbookModule() {
    	var pbModule = {
    		filepath:ko.observable('..'),
    		filelist:ko.observableArray([
    				{
			            "id": "f24c3b9c6a7ca3dd41071a2b049f4554d2a27918",
			            "name": "base",
			            "type": "tree"
			        }
    			]),
    		pathBefore:function(){
    			var self = this;
    			if(self.filepath().length>2){
    				console.log(1);
	    			var file = self.filepath();
	    			var file1 = file.substr(0,file.lastIndexOf("/"));
	    			self.filepath(file1);
	    			self.getFilelist();
    			}else{
    				alert('已经到根目录了');
    			}
    		},
    		fresh:function(){
    			window.location.reload();
    		},
    		getFilelist:function(){
    			var self = this;
    			$.ajax({
    				type:'get',
    				url:'js/json/tree.json',
    				data:{
    					filePath:self.filepath+'/'
    				},
    				success:function(data){
    					self.filelist(data.data);
    					$('.pbOperate').on('click',function(){});
			    		$('.pbOperate').on('click',function(){
			    			if($(this).html()=='打开'){
			    				var index = $(this).index('.pbOperate');
			    				self.filepath(self.filepath()+'/'+$('.pbName').eq(index).html());
			    				self.getFilelist();
			    				console.log($(this).index('.pbOperate'));
			    			}
			    		});
    				}
    			});
    		}
    	}
    	this.handleAttached = function(){
    		ko.cleanNode(document.getElementById('playbook_op'));
    		ko.applyBindings(pbModule,document.getElementById('playbook_op'));
    		pbModule.getFilelist();
    	}
	}
    
    // ko.applyBindings(homeViewModule, document.getElementsByClassName('content')[0]);
    return playbookModule;
});
